/**
 * 
 */
package gpl.scotlandyard.nodeweight;

import gpl.scotlandyard.beans.basics.Node;
import gpl.scotlandyard.services.utils.MapLoader;
import gpl.scotlandyard.utils.Config;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.prefs.InvalidPreferencesFormatException;

import org.apache.log4j.PropertyConfigurator;

/** @author norbert */
public class MapBalance {
  private static final String LOG4J_CONF_FILE = "configuration/log4j.properties";
  private static final String GAME_CONF_FILE = "configuration/scotlandyard_conf.xml";
  private static final String MAP_FILE = "configuration/map.txt";

  private static final List<Node> MAP = new ArrayList<Node>();
  static {
    BufferedReader bufr;
    try {
      bufr = new BufferedReader(new FileReader(new File(MAP_FILE)));
      MAP.addAll(MapLoader.loadMap(bufr));
    } catch (FileNotFoundException e) {
      e.printStackTrace();
      System.exit(-1);
    } catch (IOException e) {
      e.printStackTrace();
      System.exit(-1);
    }
  }

  /** @param args
   * @throws InvalidPreferencesFormatException
   * @throws IOException */
  public static void main(String[] args) throws IOException, InvalidPreferencesFormatException {
    PropertyConfigurator.configure(LOG4J_CONF_FILE);
    File conf = new File(GAME_CONF_FILE);
    Config.load(conf);

    System.out.println(MAP);
    Collections.sort(MAP, new Comparator<Node>() {
      @Override
      public int compare(Node o1, Node o2) {
        return o2.getLinks().size() - o1.getLinks().size();
      }
    });

    System.out.println(MAP);
  }

}
